/**
 * Created by Administrator on 2017/4/26.
 */

const JPush = require('jpush-sdk/lib/JPush/JPush.js');
const PromiseA = require('bluebird');
module.exports = function (options) {
    this.client = JPush.buildClient(options.appKey, options.masterSecret);
    //alert, title, builder_id, extras, priority, category, style, value, alertType
    //alert, sound, badge, contentAvailable, extras, category, mutableContent
    this.pushByRegisterId = function (registerIds, msg) {
        return PromiseA.fromCallback(cb => this.client.push().setPlatform('ios', 'android')
            .setAudience(JPush.registration_id(registerIds))
            .setNotification('Hi, JPush', JPush.ios(msg.content || ''), JPush.android(msg.content || '', msg.title || '', 1))
            .setOptions(null, 60)
            .send(cb));
    };
    return this;
};
